package com.ctf.soft.ms.service.manage.impl;

import com.ctf.soft.ms.dao.mapper.manage.HandleMapper;
import com.ctf.soft.ms.dao.mapper.manage.HandleRelationMapper;
import com.ctf.soft.ms.dao.model.manage.Handle;
import com.ctf.soft.ms.dao.model.manage.HandleRelation;
import com.ctf.soft.ms.service.impl.BaseService;
import com.ctf.soft.ms.utils.ResourceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctf.soft.ms.service.manage.IHandleService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 名称： HandleServiceImpl<br>
 * 描述： 操作动作业务处理实现类<br>
 * 最近修改时间：2015/7/31 13:21<br>
 * 修改说明：
 *
 * @author jiajl
 */
@Service
public class HandleServiceImpl extends BaseService<Handle> implements IHandleService {

    @Autowired
    private HandleMapper handleMapper;
    @Autowired
    private HandleRelationMapper handleRelationMapper;

    public List<Handle> loadPageList(Map<String, Object> map) {
        int page = Integer.valueOf(map.get("page").toString());
        int rows = Integer.valueOf(map.get("rows").toString());
        int beginRowNum = (page - 1) * rows;
        int endRowNum = page * rows;
        map.put("beginRowNum", beginRowNum);
        map.put("endRowNum", endRowNum);
        map.put("db", ResourceUtil.getString("DATA_ALIAS"));
        return handleMapper.queryForPageList(map);
    }

    public int getPageCount(Map<String, Object> map) {
        return handleMapper.queryForPageCount(map);
    }

    public int insertBatch(String parentMenu, String menuCode, String menuName) {
        List<HandleRelation> list = new ArrayList<HandleRelation>();
        String[] arrsCode = menuCode.split(",");
        String[] arrsName = menuName.split(",");
        for (int i = 0; i < arrsCode.length; i++) {
            HandleRelation handleRelation = new HandleRelation();
            int len = arrsCode[i].lastIndexOf("]") + 1;

            list.add(handleRelation);
        }
        return handleRelationMapper.insertBatch(list);
    }

    public List<HandleRelation> loadListByRelation(String mark, String code) {
        HandleRelation params = new HandleRelation();
        params.setRelationMark(mark);
        params.setRelationCode(code);
        return handleRelationMapper.select(params);
    }
}
